'Spectrum frame counter low byte
#define FRAME_LOW_BYTE 23672

'librerias
#INCLUDE <putchars.bas>
#INCLUDE <retrace.bas>
#INCLUDE <Keys.bas>

'activar o desactivar para escoger que #include se activa ENG o ESP

'#DEFINE ENGLISH_LANG


rem spectrum pantalla de 32x24 0-31 y de 0 a 23
'DIM roomType(4,4) AS UBYTE  'matriz 0-4,0-4. osea 5x5. POR CIERTO TIENE QUE DEFINIRSE ANTES DE USAR, POR EJEMPLO AQUI, JUSTO ANTES DEL INPUT.ZBAS (DONDE ES USADA)


'definiciones

DIM integerFrameCounter AS UINTEGER AT FRAME_LOW_BYTE
DIM map_pool(4, 4, 4) AS UBYTE => { _     'numero mapa, x casilla mapa,y casilla mapa)
    { {13,7,14,7,3}, {12,1,14,9,16}, {8,7,3,8,6}, {17,2,15,8,6}, {10,13,5,5,2} },_
    { {13,3,4,7,3}, {4,5,6,1,6}, {17,7,2,12,15}, {8,2,4,16,15}, {1,11,10,1,2} },_
    { {12,4,14,14,11}, {17,6,4,3,12}, {10,15,15,15,15}, {4,6,15,1,16}, {10,1,2,13,2} },_
    { {4,14,7,14,3}, {1,7,6,13,16}, {10,1,9,11,10}, {17,3,1,14,3}, {10,1,14,14,2} },_
    { {4,7,11,4,3}, {15,17,11,15,15}, {15,10,4,2,15}, {8,7,6,4,16}, {1,2,10,1,2} }_
}
Dim walls(17,3) as uByte => { _ 
    { 0,0,0,0 }, _ '0,sala tipo 1. Si tiene un 1 es que esa pared tiene puerta
    { 1,0,0,1 }, _ '1,sala tipo 2
    { 1,1,0,0 }, _
    { 0,1,1,0 }, _
    { 0,0,1,1 }, _
    { 1,1,0,1 }, _
    { 1,1,1,0 }, _
    { 0,1,1,1 }, _
    { 1,0,1,1 }, _
    { 1,1,1,1 }, _
    { 1,0,0,0 }, _
    { 0,1,0,0 }, _
    { 0,0,1,0 }, _
    { 0,0,0,1 }, _
    { 0,1,0,1 }, _
    { 1,0,1,0 }, _   'sala 15
    { 1,1,1,0 }, _   '16, entrada
    { 1,2,1,1 } _    '17, salida
    }     
DIM map_events(4,4) AS UBYTE 
DIM respuestas(12) AS UBYTE => {1,2,3,1,2,3,1,2,3,1,2,3,2}
DIM preguntas_barajadas(12) AS Ubyte
DIM usedMaps(4) AS UBYTE 
DIM room,wallsMoving AS UBYTE
DIM current_map,levelCompleted AS UBYTE
DIM pl_x,pl_y,plSubX,plSubY AS UBYTE
DIM playerDir,playerFrom AS UBYTE
DIM counter,controllerType AS UBYTE
DIM llave,barraAnterior,respuesta,num_pregunta AS UBYTE
DIM player_hp AS UBYTE
DIM level,soundStep,respuestaRandom AS UBYTE
DIM time_total,time_left AS UBYTE
DIM difficulty,endGame AS UBYTE
DIM score,maxScore,key AS UINTEGER
DIM keyString AS STRING


'incluye para texto en castellano o inglés
#IFDEF ENGLISH_LANG
        #include "common\textENG.zxbas"
#ELSE
        #include "common\text.zxbas"
#ENDIF 

'includes de la carpeta common o tiles

#include "tiles\maps.zxbas"
#include "tiles\tiles.spr.bas"
#include "tiles\hudTiles.spr.bas"
#include "common\input.zxbas"
#include "common\engine.zxbas"
#include "common\graphics.zxbas"
#include "common\sound.zxbas"
#include "common\Beastly.fnt.zxbas"


'fuente Beastly de DamienG  
POKE UINTEGER 23606,@Beastly-256



'nueva partida
SUB new_game()
    level=0
    score=0
    showNextLevel()
    reset_vars()
    resetUsedMaps()
    choose_map()
    shuffle_preguntas()
   
   'test
    'testPreguntas()
    
    set_map_events()
    integerFrameCounter=0   
   

END sub

'rutina motor principal del juego
SUB next_room()
    
    DO
    roomBundle()
    check_events()
    IF endGame=0
            check_ways()   
            IF levelCompleted=1 then levelClear()
       
    END IF
    
    LOOP UNTIL endGame=1
        
    IF maxScore<score then  maxScore=score
    
    credits()
    mainMenu()

END SUB


'---------PROGRAMA PRINCIPAL------

'post pantalla carga
BORDER 0
PAPER 0
playSFX5()
pressAnyKey()

'INICIO
showLogo()
END
